package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsUser;
import com.qf.pojo.DtsUserAccount;
import com.qf.service.DtsUserAccountService;
import com.qf.service.DtsUserService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/admin/user")
public class DtsAdminUserController {

    @Autowired
    DtsUserService userService;

    @Autowired
    DtsUserAccountService userAccountService;

    @RequestMapping("/detailApprove")
    public Object detailApprove(Integer id){
        DtsUserAccount userAccount = userAccountService.queryById(id);
        return ResponseUtil.ok(userAccount);
    }

    @RequestMapping("/approveAgency")
    public Object approveAgency(@RequestBody Map<String,Object> map){
        String settlementRate = (String) map.get("settlementRate");
        int userId = (int) map.get("userId");
        userService.updateByUserLevelAndStatus(userId);

        userAccountService.updateByUserIdAndSettlementRate(userId,settlementRate);

        return ResponseUtil.ok();
    }

    @GetMapping("/list")
    public Object list(@RequestParam(value = "page",required = false,defaultValue = "1") Integer page,
                       @RequestParam(value = "limit",required = false,defaultValue = "10")Integer limit,
                       String sort, String order, String username, String mobile){

        IPage<DtsUser> iPage = userService.queryPage(page,limit,sort,order,username,mobile);

        Map<String,Object> data = new HashMap<>();
        data.put("total",iPage.getTotal());
        data.put("items",iPage.getRecords());
        return ResponseUtil.ok(data);
    }
}
